
<template>
    <div class="search">
        <Row :gutter="16" class="all-height">
            <Col :span="showRight ? 18 : 24" class="all-height">
                <Card class="all-height card-child-height">
                    <Row class="operation code-row-bg" style="display: flex; justify-content: space-between">
                        <Col span="22">
                            <Button v-has="'add'" @click="add" type="primary" icon="md-add">添加账号</Button>
                            <Button v-has="'delete'" @click="delAll" icon="md-trash">批量删除</Button>
                            <Button v-has="'clear'" @click="clearData" icon="md-trash">清空数据</Button>
                            <Button v-has="'other'" @click="dropReset">重置用户密码</Button>
                            <Button v-has="'input'" @click="dropImportData">导入数据</Button>
                            <Button v-has="'output'" @click="dropExportData">导出所选数据</Button>
                            <Button v-has="'output'" @click="dropExportAll">导出全部数据</Button>
                        </Col>
                        <Col span="2" style="text-align: right">
                            <Button :icon="showRight ? `ios-arrow-forward` : `ios-arrow-back`" @click.native="clickShowRight" type="primary"></Button>
                        </Col>
                    </Row>
                    <Row v-show="openTip">
                        <Alert show-icon>
                            已选择
                            <span class="select-count">{{ selectList.length }}</span>
                            项
                            <a class="select-clear" @click="clearSelectAll">清空</a>
                            <a class="select-clear" style="cursor: pointer" @click="getDataList">刷新</a>
                        </Alert>
                    </Row>
                    <Row class="calc-px-height">
                        <Table
                            :height="height1"
                            :loading="loading"
                            border
                            :columns="columns"
                            :data="data"
                            sortable="custom"
                            @on-sort-change="changeSort"
                            @on-selection-change="showSelect"
                            @on-row-dblclick="sjclaib"
                            no-filtered-data-text="暂无数据"
                            ref="table"
                        ></Table>
                    </Row>
                    <Row type="flex" justify="end" class="page">
                        <Page
                            :current="searchForm.pageNumber"
                            :total="total"
                            :page-size="searchForm.pageSize"
                            @on-change="changePage"
                            @on-page-size-change="changePageSize"
                            :page-size-opts="[10, 20, 50, 100, 200]"
                            size="small"
                            show-total
                            show-elevator
                            show-sizer
                        ></Page>
                    </Row>
                </Card>
            </Col>
            <Col span="6" class="all-height" v-show="showRight">
                <Card class="all-height card-child-height">
                    <Row v-show="openSearch" @keydown.enter.native="handleSearch">
                        <Col span="24">
                            <div class="drawer-header">
                                <div class="cmr16">查询区</div>
                            </div>
                        </Col>
                       <Col span="24">
                            <Form ref="searchForm" :model="searchForm" :label-width="labelWidth100">
                                <FormItem label="账号" prop="username" style="width: 100%">
                                    <Input type="text" v-model="searchForm.username" clearable placeholder="请输入账号" />
                                </FormItem>
                                <FormItem label="姓名" prop="name" style="width: 100%">
                                    <Input type="text" v-model="searchForm.name" clearable placeholder="请输入姓名" />
                                </FormItem>

                                <div v-if="drop">
                                    <FormItem label="所在高校" prop="gxcode" style="width: 100%">
                                        <Input type="text" v-model="searchForm.gxmc" placeholder="请输入学校名称" clearable />
                                        <!--                    <Select v-model="searchForm.gxcode" placeholder="请选择" clearable>-->
                                        <!--                      <Option value="0">请自行编辑下拉菜单</Option>-->
                                        <!--                    </Select>-->
                                    </FormItem>
                                    <!--                <FormItem label="部门名称" prop="department" style="width: 100%">-->
                                    <!--                  <department-choose-->
                                    <!--                      @on-change="handleSelectDep"-->
                                    <!--                      ref="dep"-->
                                    <!--                  ></department-choose>-->
                                    <!--                </FormItem>-->
                                    <FormItem label="管理的学历层次" prop="glxlcc" style="width: 100%">
                                        <Select v-model="searchForm.glxlcc" placeholder="请选择" clearable multiple>
                                            <Option v-for="item in glxlccList" :value="item.value" :key="item.id">{{ item.title }}</Option>
                                        </Select>
                                    </FormItem>
                                    <FormItem label="职务" prop="zw" style="width: 100%">
                                        <Input type="text" v-model="searchForm.zw" placeholder="请输入职务" clearable />
                                    </FormItem>
                                    <FormItem label="电话" prop="telephone" style="width: 100%">
                                        <Input type="text" v-model="searchForm.telephone" placeholder="请输入电话" clearable />
                                    </FormItem>
                                    <FormItem label="手机号" prop="mobile" style="width: 100%">
                                        <Input type="text" v-model="searchForm.mobile" clearable placeholder="请输入手机号" />
                                    </FormItem>
                                    <FormItem label="传真" prop="fax" style="width: 100%">
                                        <Input type="text" v-model="searchForm.fax" placeholder="请输入传真" clearable />
                                    </FormItem>
                                    <FormItem label="邮箱" prop="email" style="width: 100%">
                                        <Input type="text" v-model="searchForm.email" clearable placeholder="请输入邮箱" />
                                    </FormItem>
                                    <FormItem label="QQ" prop="qq" style="width: 100%">
                                        <Input type="text" v-model="searchForm.qq" placeholder="请输入QQ" clearable />
                                    </FormItem>
                                    <FormItem label="排序值" prop="sortorder" style="width: 100%">
                                        <Input type="text" v-model="searchForm.sortorder" placeholder="请输入排序值" clearable />
                                    </FormItem>
                                    <FormItem label="状态" prop="status" style="width: 100%">
                                        <Select v-model="searchForm.status" placeholder="请选择" clearable>
                                            <Option value="0">正常</Option>
                                            <Option value="-1">禁用</Option>
                                        </Select>
                                    </FormItem>
                                    <FormItem label="创建时间" style="width: 100%">
                                        <DatePicker
                                            :options="options"
                                            v-model="selectDate"
                                            type="daterange"
                                            format="yyyy-MM-dd"
                                            clearable
                                            @on-change="selectDateRange"
                                            placeholder="选择起始时间"
                                            style="width: 100%"
                                        ></DatePicker>
                                    </FormItem>
                                </div>
                                <FormItem class="br right-bottom">
                                    <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                                    <Button @click="handleReset">重置</Button>
                                    <!-- <a class="drop-down" @click="dropDown">
                        {{ dropDownContent }}
                        <Icon :type="dropDownIcon"></Icon>
                    </a> -->
                                </FormItem>
                            </Form>
                        </Col>
                    </Row>
                    <Row class="calc-sm-height" v-show="!openSearch">
                        <addEdit :data="form" ref="addOrEdit" :type="showType" v-model="showUser" @on-submit="getDataList" @open-search="changeOpenSearch" />
                    </Row>
                </Card>
            </Col>
        </Row>
        <check-password ref="checkPass" @on-success="resetPass" />

        <Modal class="cw360" :title="'导入结果'" v-model="show">
            <div>
                {{ importResult }}
            </div>
            <div class="tableStyle" v-show="showerror">
                <Table height="100%" width='400' :columns="errcolumns" :data="errorList"></Table>
            </div>
        </Modal>

        <Drawer title="导入数据" closable v-model="importModalVisible" class="cw1000">
            <div style="display: flex; justify-content: space-between; align-items: center">
                <Upload action :before-upload="beforeUploadImport" accept=".xls, .xlsx">
                    <Button :loading="reading" icon="ios-cloud-upload-outline" class="cmr10">上传Excel文件</Button>
                    <span v-if="uploadfile.name">当前选择文件：{{ uploadfile.name }}</span>
                </Upload>
                <Button @click="clearImportData" icon="md-trash">清空数据</Button>
            </div>
            <Alert type="warning" show-icon>导入前请下载查看导入模版数据文件查看所需字段及说明，确保数据格式正确，不得修改列英文名称</Alert>
            <Table :columns="importColumns" border :height="height" :data="importTableData" ref="importTable"></Table>
            <div class="drawer-footer">
                <Button @click="downloadTemple" type="info">下载导入模板</Button>
                <div class="wrapper01">
                    <Button @click="importModalVisible = false">关闭</Button>
                    <Button :loading="importLoading" :disabled="importTableData.length <= 0" @click="importData" class="cml10"  type="primary">
                        确认导入
                        <span v-if="importTableData.length > 0">{{ importTableData.length }} 条数据</span>
                    </Button>
                </div>
            </div>
        </Drawer>
        <!-- 自定义导出数据 -->
        <Modal class="cust-export-modal" v-model="exportModalVisible" :title="exportTitle" :loading="loadingExport" @on-ok="exportCustomData">
            <Form ref="exportForm" :label-width="labelWidth100">
                <FormItem label="导出文件名">
                    <Input v-model="filename" />
                </FormItem>
                <FormItem label="自定义导出列">
                    <CheckboxGroup v-model="chooseColumns">
                        <Checkbox v-for="(item, i) in exportColumns" :label="item.title" :key="i" :value="item.checked" :disabled="item.disabled"></Checkbox>
                    </CheckboxGroup>
                </FormItem>
            </Form>
        </Modal>
    </div>
</template>

<script>
import { getSchoolPersonInfoList, enableSchoolPersonInfo, disableSchoolPersonInfo, deleteSchoolPersonInfo } from '@/api/bys/personInfo/school';
import { getDictDataByType, getRoles as getRoleList, getSchoolPersonInfoData, importProvinceData, importschoolPersonData, resetUserPass } from '@/api/index';
import departmentChoose from '@/views/my-components/xboot/department-choose';
import checkPassword from '@/views/my-components/xboot/check-password';
import { shortcuts } from '@/libs/shortcuts';
import addEdit from './addEditSchool.vue';
import dict from '@/views/my-components/xboot/dict';
import excel from '@/libs/excel';
// 指定导出列数据
import { exportColumn } from './exportColumn';
import { delAllAPI } from '../../../api/bys/destinationAfterGraduation';

export default {
    name: 'user-manage',
    components: {
        departmentChoose,
        checkPassword,
        addEdit,
        dict
    },
    data() {
        return {
            labelWidth100: 100,
            importResult: '',
            show: false,
            showerror: false,
            roleList: [],
            height: 510,
            showUser: false,
            showType: '0',
            openSearch: true,
            openTip: true,
            loading: true,
            drop: true,
            dropDownContent: '展开',
            dropDownIcon: 'ios-arrow-down',
            errorList: [],
            selectList: [],
            exportModalVisible: false,
            exportTitle: '确认导出',
            filename: '学校信息数据',
            loadingExport: true,
            chooseColumns: [],
            exportColumns: exportColumn,
            exportType: '',
            exportData: [],
            glxlccList: [],
            height1: 0,
            searchForm: {
                id: '',
                name: '',
                username: '',
                departmentid: '',
                mobile: '',
                email: '',
                status: '',
                pageNumber: 1,
                pageSize: 50,
                // sort: "createTime",
                // order: "desc",
                startDate: '',
                endDate: '',
                sortorder: ''
            },
            selectDate: null,
            options: {
                shortcuts: shortcuts
            },
            form: {
                sortorder: 1
            },
            errcolumns: [
                {
                    title: '行号',
                    key: 'row'
                },
                {
                    title: '原因',
                    key: 'reason'
                }
            ],
            columns: [],
            columns_1: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                    //fixed: "left",
                },
                {
                    type: 'index',
                    title: '序号',
                    width: 60,
                    align: 'center'
                    //fixed: "left",
                },
                {
                    title: '账号',
                    key: 'username',
                    minWidth: 120,
                    sortable: true
                    //fixed: "left",
                },
                {
                    title: '姓名',
                    key: 'name',
                    minWidth: 160,
                    sortable: true,
                    //fixed: "left",
                    render: (h, params) => {
                        return h(
                            'a',
                            {
                                on: {
                                    click: () => {
                                        this.showDetail(params.row);
                                    }
                                }
                            },
                            params.row.name
                        );
                    }
                },
                {
                    title: '所在高校',
                    key: 'gxmc',
                    minWidth: 180,
                    sortable: false
                },
                {
                    title: '角色',
                    key: 'roles',
                    minWidth: 300,
                    render: (h, params) => {
                        let dict = '';
                        // console.log(params.row.roles, '角色');
                        this.roleList.forEach(item => {
                            if (params.row.roles) {
                                // console.log('dict', dict);
                                params.row.roles.forEach(e => {
                                    if (item.name === e.name) {
                                        dict += item.description + ',';
                                    }
                                });
                            }
                        });
                        return h('p', dict ? dict.slice(0, dict.length - 1) : '');
                    }
                },
                // {
                //   title: "部门名称",
                //   key: "departmenttitle",
                //   minWidth: 120,
                // },
                {
                    title: '管理的学历层次',
                    key: 'glxlcc',
                    minWidth: 120,
                    sortable: false,
                    render: (h, params) => {
                        let dict = '';
                        this.glxlccList.forEach(item => {
                            if (params.row.glxlcc) {
                                let glxlcc = params.row.glxlcc.split(',');
                                glxlcc.forEach(e => {
                                    if (item.value === e) {
                                        dict += item.title + ',';
                                    }
                                });
                            }
                        });
                        return h('p', dict ? dict.slice(0, dict.length - 1) : '');
                    }
                },
                {
                    title: '职务',
                    key: 'zw',
                    minWidth: 120,
                    sortable: false
                },
                {
                    title: '电话',
                    key: 'telephone',
                    minWidth: 120,
                    sortable: false
                },
                {
                    title: '手机',
                    key: 'mobile',
                    minWidth: 100,
                    sortable: true
                },
                {
                    title: '传真',
                    key: 'fax',
                    minWidth: 120,
                    sortable: false
                },
                {
                    title: '邮箱',
                    key: 'email',
                    minWidth: 140,
                    sortable: true
                },
                {
                    title: 'QQ',
                    key: 'qq',
                    minWidth: 120,
                    sortable: false
                },
                {
                    title: '排序号',
                    key: 'sortorder',
                    minWidth: 80,
                    sortable: true,
                    sortType: 'asc',
                    sortMethod(a,b,type){
                        // 如果两者都是 null，则视为相等
                        if (!a  && !b) {
                            return 0;
                        }
                        // 如果 a 是 null，则 b 排在 a 前面
                        else if (!a) {

                            return 1;
                        }
                        // 如果 b 是 null，则 a 排在 b 前面
                        else if (!b) {

                            return -1;
                        }
                        // 对于非 null 值，进行正常数值比较
                        else {
                            if(type=='desc'){
                                if(a>b){
                                    return -1;
                                }
                                if(a<b){
                                    return 1;
                                }
                                return 0;
                            }else{
                                if(a>b){
                                    return 1;
                                }
                                if(a<b){
                                    return -11;
                                }
                                return 0;
                            }
                        }
                    },
                },
                {
                    title: '状态',
                    key: 'status',
                    align: 'center',
                    minWidth: 80,
                    fixed: 'right',
                    render: (h, params) => {
                        if (params.row.status == 0) {
                            return h('div', [
                                h('Badge', {
                                    props: {
                                        status: 'success',
                                        text: '启用'
                                    }
                                })
                            ]);
                        } else if (params.row.status == -1) {
                            return h('div', [
                                h('Badge', {
                                    props: {
                                        status: 'error',
                                        text: '禁用'
                                    }
                                })
                            ]);
                        }
                    },
                    filters: [
                        {
                            label: '启用',
                            value: 0
                        },
                        {
                            label: '禁用',
                            value: -1
                        }
                    ],
                    filterMultiple: false,
                    filterRemote: e => {
                        let v = '';
                        if (e.length > 0) {
                            v = e[0];
                        }
                        this.searchForm.status = v;
                        this.searchForm.pageNumber = 1;
                        this.getDataList();
                    }
                },
                {
                    title: '创建时间',
                    key: 'createTime',
                    sortable: true,
                    sortType: 'desc',
                    minWidth: 160
                },
                {
                    title: '操作',
                    key: 'action',
                    width: 160,
                    align: 'center',
                    fixed: 'right',
                    render: (h, params) => {
                        let enableOrDisable = '';
                        if (params.row.status == 0) {
                            enableOrDisable = h(
                                'a',
                                {
                                    style: {
                                        display: this.hasPermission(this, 'disable') ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.disable(params.row);
                                        }
                                    }
                                },
                                '禁用'
                            );
                        } else {
                            enableOrDisable = h(
                                'a',
                                {
                                    style: {
                                        display: this.hasPermission(this, 'enable') ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.enable(params.row);
                                        }
                                    }
                                },
                                '启用'
                            );
                        }
                        return h('div', [
                            h(
                                'a',
                                {
                                    style: {
                                        display: this.hasPermission(this, 'edit') ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.edit(params.row);
                                        }
                                    }
                                },
                                '编辑'
                            ),
                            h('Divider', {
                                props: {
                                    type: 'vertical'
                                }
                            }),
                            enableOrDisable,
                            h('Divider', {
                                props: {
                                    type: 'vertical'
                                }
                            }),
                            h(
                                'a',
                                {
                                    style: {
                                        display: this.hasPermission(this, 'delete') ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.row);
                                        }
                                    }
                                },
                                '删除'
                            )
                        ]);
                    }
                }
            ],
            // uploadfile: {
            //   name: "",
            // },
            data: [],
            // exportData: [],
            total: 0,
            showRight: true,
            importModalVisible: false,
            importTableData: [],
            importColumns: [],
            uploadfile: {
                name: ''
            },
            reading: false,
            importLoading: false
        };
    },
    created() {},
    methods: {
        // region TODO 清空数据
        clearData() {
            this.$confirm('此操作将永久删除数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    delAllAPI().then(res => {
                        if (res.success) {
                            this.$message.success(res.message);
                            this.getTableData();
                            this.getDataList();
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
        },
        // endregion
        tableheig() {
            var bbb = document.getElementsByClassName('calc-px-height')[0].scrollHeight;
            var aaa = document.getElementsByClassName('calc-px-height')[0].children[0].children[0].children[1];
            var ccc = document.getElementsByClassName('calc-px-height')[0].children[0].children[0].children[0].scrollHeight;
            var ddd = bbb - ccc;
            // console.log(bbb, '00000000000000');
            aaa.style.height = `${ddd}px`;

            if (this.searchForm.pageSize === 10) {
                this.height1 = 0;
            } else {
                this.height1 = document.getElementsByClassName('calc-px-height')[0].scrollHeight;
                if (this.total < this.searchForm.pageNumber * this.searchForm.pageSize) {
                    var r = (this.searchForm.pageNumber - 1) * this.searchForm.pageSize;
                    var a = this.total - r;
                    var s = a * 43 + 65;
                    if (s < this.height1) {
                        this.height1 = 0;
                    }
                }
            }
            if (this.total < 10) {
                this.height1 = 0;
            }
        },
        init() {
            // console.log(this);
            this.getDataList();
            this.getGlxlccDataList();
            this.getRoleList();
            // 初始化导出列数据
            let array = [];
            this.exportColumns.forEach(e => {
                // 指定列限制权限
                if (!this.getStore('roles').includes('ROLE_ADMIN') && e.key == 'mobile') {
                    e.title = '[无权导出] ' + e.title;
                    e.disabled = true;
                } else {
                    e.disabled = false;
                }
                array.push(e.title);
            });
            this.chooseColumns = array;
        },
        // 显示隐藏右侧区域
        clickShowRight() {
            this.showRight = !this.showRight;
        },
        getRoleList() {
            getRoleList({ level: 'school' }).then(res => {
                if (res.success) {
                    console.log(res.result);
                    this.roleList = res.result;
                }
            });
        },
        handleSelectDep(v) {
            this.searchForm.departmentid = v;
        },
        changePage(v) {
            this.searchForm.pageNumber = v;
            this.getDataList();
            this.clearSelectAll();
        },
        changePageSize(v) {
            this.searchForm.pageSize = v;
            this.getDataList();
        },
        selectDateRange(v) {
            if (v) {
                this.searchForm.startDate = v[0];
                this.searchForm.endDate = v[1];
            }
        },
        getDataList() {
            this.loading = true;
            getSchoolPersonInfoList(this.searchForm).then(res => {
                this.loading = false;
                if (res.success) {
                    console.log(res.result.result, '学校账号');
                    this.data = res?.result?.result || [];
                    this.total = res?.result?.total || 0;
                    this.tableheig();
                }
            });
        },
        changeOpenSearch() {
            this.openSearch = true;
        },
        handleSearch() {
            this.searchForm.pageNumber = 1;
            this.searchForm.pageSize = 50;
            this.getDataList();
        },
        getGlxlccDataList() {
            // 学历层次
            getDictDataByType('eduLevelType').then(res => {
                if (res.success) {
                    this.glxlccList = res.result;
                }
            });
        },
        handleReset() {
            this.$refs.searchForm.resetFields();
            this.searchForm.pageNumber = 1;
            this.searchForm.pageSize = 50;
            this.selectDate = null;
            this.searchForm.startDate = '';
            this.searchForm.endDate = '';
            this.$refs.dep.clearSelect();
            this.searchForm.departmentid = '';
            // 重新加载数据
            this.getDataList();
        },
        changeSort(e) {
            this.searchForm.sort = e.key;
            this.searchForm.order = e.order;
            if (e.order == 'normal') {
                this.searchForm.order = '';
            }
            this.getDataList();
        },
        //重置用户密码
        dropReset() {
            if (this.selectList.length <= 0) {
                this.$Message.warning('您还未选择要重置密码的用户');
                return;
            }
            this.$refs.checkPass.show();
        },

        resetPass(e, i) {
            this.$Modal.confirm({
                title: '确认重置',
                content: '您确认要重置所选的 ' + this.selectList.length + ' 条用户数据密码为' + i + '吗？',
                loading: true,
                onOk: () => {
                    let ids = '';
                    this.selectList.forEach(function (e) {
                        ids += e.userid + ',';
                    });
                    ids = ids.substring(0, ids.length - 1);
                    resetUserPass({ ids: ids, password: i }).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success('操作成功');
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        showDetail(v) {
            // 转换null为""
            for (let attr in v) {
                if (v[attr] == null) {
                    v[attr] = '';
                }
            }
            let str = JSON.stringify(v);
            let data = JSON.parse(str);
            this.form = data;
            this.showType = '0';
            this.showUser = true;
        },
        add() {
            this.showType = '2';
            this.showUser = true;
            this.openSearch = false;
            this.$refs.addOrEdit.form = {};
        },
        sjclaib(v) {
            this.showRight = true;
            // 转换null为""
            for (let attr in v) {
                if (v[attr] == null) {
                    v[attr] = '';
                }
            }
            let str = JSON.stringify(v);
            let data = JSON.parse(str);
            this.form = data;
            this.showType = '1';
            this.showUser = true;
            this.openSearch = false;
            this.$refs.addOrEdit.form = data;
        },
        edit(v) {
            // 转换null为""
            for (let attr in v) {
                if (v[attr] == null) {
                    v[attr] = '';
                }
            }
            let str = JSON.stringify(v);
            let data = JSON.parse(str);
            this.form = data;
            this.showType = '1';
            this.showUser = true;
            this.openSearch = false;
            this.$refs.addOrEdit.form = data;
        },
        enable(v) {
            this.$Modal.confirm({
                title: '确认启用',
                content: '您确认要启用用户 ' + v.username + ' ?',
                loading: true,
                onOk: () => {
                    enableSchoolPersonInfo(v.id).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success('操作成功');
                            this.getDataList();
                        }
                    });
                }
            });
        },
        disable(v) {
            this.$Modal.confirm({
                title: '确认禁用',
                content: '您确认要禁用用户 ' + v.username + ' ?',
                loading: true,
                onOk: () => {
                    disableSchoolPersonInfo(v.id).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success('操作成功');
                            this.getDataList();
                        }
                    });
                }
            });
        },
        remove(v) {
            this.$Modal.confirm({
                title: '确认删除',
                content: '您确认要删除用户 ' + v.username + ' ?',
                loading: true,
                onOk: () => {
                    deleteSchoolPersonInfo({ ids: v.id }).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.clearSelectAll();
                            this.$Message.success('删除成功');
                            this.getDataList();
                        }
                    });
                }
            });
        },
        dropDown() {
            if (this.drop) {
                this.dropDownContent = '展开';
                this.dropDownIcon = 'ios-arrow-down';
            } else {
                this.dropDownContent = '收起';
                this.dropDownIcon = 'ios-arrow-up';
            }
            this.drop = !this.drop;
        },
        showSelect(e) {
            this.exportData = e;
            this.selectList = e;
        },
        clearSelectAll() {
            this.$refs.table.selectAll(false);
        },
        delAll() {
            if (this.selectList.length <= 0) {
                this.$Message.warning('您还未选择要删除的数据');
                return;
            }
            this.$Modal.confirm({
                title: '确认删除',
                content: '您确认要删除所选的 ' + this.selectList.length + ' 条数据?',
                loading: true,
                onOk: () => {
                    let ids = '';
                    this.selectList.forEach(function (e) {
                        ids += e.id + ',';
                    });
                    ids = ids.substring(0, ids.length - 1);
                    deleteSchoolPersonInfo({ ids: ids }).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success('删除成功');
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        //导出所选数据
        dropExportData() {
            if (this.selectList.length <= 0) {
                this.$Message.warning('您还未选择要导出的数据');
                return;
            }
            this.exportType = 'part';
            this.exportModalVisible = true;
            this.exportTitle = '确认导出 ' + this.selectList.length + ' 条数据';
            // "确认导出 " + this.selectList.length + " 条数据(付费)";
        },
        //导出全部数据
        dropExportAll() {
            this.exportType = 'all';
            this.exportModalVisible = true;
            this.exportTitle = '确认导出全部 ' + this.total + ' 条数据';
            // this.exportTitle = "确认导出全部 " + this.total + " 条数据(付费)";
            getSchoolPersonInfoData().then(res => {
                if (res.success) {
                    this.exportData = res.result;
                }
            });
        },
        exportCustomData() {
            if (this.filename === '') {
                this.filename = '学校账号信息';
            }
            // 判断勾选导出列
            let array = [];
            this.exportColumns.forEach(e => {
                this.chooseColumns.forEach(c => {
                    if (e.title == c && !e.disabled) {
                        array.push(e);
                    }
                });
            });
            this.exportColumns = array;
            this.exportModalVisible = false;
            let title = [];
            let key = [];
            this.exportColumns.forEach(e => {
                title.push(e.title);
                key.push(e.key);
            });
            let rolex=[
                {
                    value: "ROLE_PROVINCE",
                    name: "省级管理员"
                },
                {
                    value: "ROLE_USER",
                    name: "毕业生"
                },
                {
                    value: "ROLE_SCHOOL",
                    name: "高校管理员"
                },
                {
                    value: "ROLE_COLLEGE",
                    name: "院系管理员"
                },
                {
                    value: "ROLE_DANGAN",
                    name: "档案信息管理员"
                },
                {
                    value: "ROLE_HUKOU",
                    name: "户口信息管理员"
                },
                {
                    value: "ROLE_JIUYE",
                    name: "就业信息管理员"
                },
                {
                    value: "ROLE_BASE",
                    name: "基础信息管理员"
                },
                {
                    value: "ROLE_HARD",
                    name: "困难帮扶管理员"
                },
                {
                    value: "ROLE_MARKET",
                    name: "分市场管理员"
                },
                {
                    value: "ROLE_PROVINCE_MARKET",
                    name: "省市场管理员"
                },
                {
                    value: "ROLE_RECRUIT",
                    name: "招聘信息管理员"
                },
            ]
            let glxlccList=[
                {
                    value: "0",
                    title: "专科"
                },
                {
                    value: "1",
                    title: "本科"
                },
                {
                    value: "2",
                    title: "研究生"
                },
            ]
            let excelexportData = this.exportData;
            if(excelexportData.length > 0){
                for (let excelexportDatum of excelexportData) {
                    if(excelexportDatum.roles){
                        let dict = '';
                        rolex.forEach(item => {
                            if (excelexportDatum.roles) {
                                // console.log('dict', dict);
                                let roles = JSON.parse(excelexportDatum.roles);
                                roles.forEach(e => {
                                    if (item.value === e.name) {
                                        dict += item.name + ',';
                                    }
                                });
                            }
                        });
                        excelexportDatum.roles=dict
                    }
                    if(excelexportDatum.glxlcc){
                        let dict = '';
                        glxlccList.forEach(item => {
                                let glxlcc =excelexportDatum.glxlcc.split(',');
                                glxlcc.forEach(e => {
                                    if (item.value === e) {
                                        dict += item.title + ',';
                                    }
                                });

                        });
                        excelexportDatum.glxlcc=dict
                    }
                        console.log("excelexportDatum.status",excelexportDatum.status)
                        if(excelexportDatum.status === '0'){
                            let dict ='启用'
                            excelexportDatum.status=dict
                        }else if(excelexportDatum.status == -1){
                            let dict ='禁用'
                            excelexportDatum.status=dict
                        }

                }
            }
            const params = {
                title: title,
                key: key,
                data: excelexportData,
                autoWidth: true,
                filename: this.filename
            };
            console.log(params, '导出参数');
            excel.export_array_to_excel(params);
        },
        dropImportData() {
            this.importModalVisible = true;
        },
        beforeUploadImport(file) {
            this.uploadfile = file;
            const fileExt = file.name.split('.').pop().toLocaleLowerCase();
            if (fileExt == 'xlsx' || fileExt == 'xls') {
                this.readFile(file);
                this.file = file;
            } else {
                this.$Notice.warning({
                    title: '文件类型错误',
                    desc: '所选文件‘ ' + file.name + ' ’不是EXCEL文件，请选择后缀为.xlsx或者.xls的EXCEL文件。'
                });
            }
            return false;
        },
        readFile(file) {
            this.reading = true;
            const reader = new FileReader();
            reader.readAsArrayBuffer(file);
            reader.onerror = e => {
                this.reading = false;
                // this.$Message.error("文件读取出错");
                this.$Message.error({
                    content: '文件读取出错',
                    duration: 5,
                    closable: true
                });
            };
            reader.onload = e => {
                const data = e.target.result;
                const { header, results } = excel.read(data, 'array');
                let tableTitle = header.map(item => {
                    return { title: item, key: item, minWidth: 130, align: 'center' };
                });

                tableTitle = this.restTableCellWidth(tableTitle)

                this.importTableData = results;
                this.importColumns = tableTitle.filter(e => e.title != '密码(必填)');
                this.reading = false;
                this.$Message.success('读取数据成功');
            };
        },
        clearImportData() {
            this.importTableData = [];
            this.importColumns = [];
            this.uploadfile = {};
        },
        downloadTemple() {
            window.location.href = process.env.BASE_URL + '学校账号数据导入模板.xlsx';
        },
        importData() {
            let params = this.importTableData.map(item => {
                return {
                    username: item['用户名(登录账号不能包含特殊字符且长度不能>16)'],
                    password: item['密码(密码长度不得小于8位，且应为数字、大小写字母和特殊字符混合组成)'],
                    name: item['姓名'],
                    gxcode: item['学校代码'],
                    gxmc: item['学校名称'],
                    zw: item['职务'],
                    telephone: item['电话'],
                    mobile: item['手机号'],
                    fax: item['传真'],
                    email: item['邮箱'],
                    qq: item['QQ'],
                    sortorder: item['排序值']
                };
            });
            this.importLoading = true;
            importschoolPersonData(params).then(res => {
                console.log(params)
                this.importLoading = false;
                if (res.success) {
                    this.importModalVisible = false;
                    this.getDataList();
                    this.errorList = res.result.importErrorVoList
                    this.importResult = res.result.result
                    this.show = true
                    if(this.errorList.length > 0){
                        this.showerror = true
                    }
                }
            });
        },
        onRestWindow() {
            this.columns = this.restTableCellWidth(this.columns_1)
            this.labelWidth100 = this.searchLabelWidth(this.labelWidth100)
        }
    },
    beforeDestroy() {
        window.removeEventListener('resize',this.onRestWindow)
    },
    mounted() {

        this.onRestWindow()
        window.addEventListener('resize',this.onRestWindow)
        // 计算高度
        this.height = Number(document.documentElement.clientHeight - 230);
        this.init();
    }
};
</script>
<style lang="less" scoped>
@import '../../../styles/table-common.less';
@import '../../personInfo.less';
/deep/ .ivu-table-body {
    // height: 90.6% !important;
}

.tableStyle{
    height: 300px;
    overflow-y: auto;
}

.cmr16 {
    margin-right: 16px
}
.cmr10 {
    margin-right: 10px
}
.wrapper01 {
   position: absolute; right: 15px; display: inline-block
}
.cml10 {
    margin-left: 8px
}

.cust-export-modal {
    width: 30%;
}

.cw1000 {
  /deep/.ivu-drawer {
    width: 1000px !important;
  }
}

.cw360 {
    width: 360
}

@media (max-width: 1920px) {
    /deep/ .ivu-table .ivu-table-fixed-right{
        height: 98% !important;
    }
    /deep/ .ivu-table .ivu-table-fixed-right  .ivu-table-fixed-body {
        height: 94% !important;
    }
        
}
</style>